home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 34
/
Amiga Format CD34 (1998-11-20)(Future Publishing)(GB)[!][Christmas issue].iso
/
-seriously_amiga-
/
programming
/
c
/
viewperf5.1
/
viewperf
/
envaos.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-10-01
|
33KB
|
1,058 lines
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <math.h>
#include "Env.h"
#include <malloc.h>
#include <gl/glaux.h>
#include "viewperf.h"
static char *GetShortVendorName(char *input);
static int GetHostMemorySize(void);
static char *GetHostVendor(void);
static char *GetHostModel(void);
static char *GetHostCPU(void);
static char *GetHostOperatingSystem(void);
static char *GetHostOperatingSystemRelease(void);
static char *GetHostName(void);
static char *GetOpenGLClientVendor(void);
static char *GetOpenGLClientVersion(void);
static char *GetOpenGLClientExtensions(void);
static char *GetHostCPUCount(void);
static char *GetHostPrimaryCacheSize(void);
static char *GetHostSecondaryCacheSize(void);
static char *GetWindowSystem(void);
static char *GetDriverVersion(void);
/******************************************************************************
*
* StringSearch - search for pattern in string
*
* Description:
* StringSearch returns a pointer to the first occurance of pattern found in
* the subject or NULL if the pattern is not found. It implements the
* Knuth-Morris-Pratt pattern matching algorithm. If m is the length of the
* pattern and n is the length of the subject, the complexity of the KMP
* algorithm is (m+n), much better than the (m*n) complexity of the naive
* nested loop algorithm. - John Dennis
*
* Returns:
* pointer to the first occurance of pattern found the subject or NULL
*
* Side Effects:
* None
*
* Errors:
* None
*
* Revision History:
* Revision 0: Author: John R. Dennis Date: Thu Aug 4 15:49:59 1994
* Initial Release
*
*****************************************************************************/
char *
StringSearch(char *subject, char *pattern)
{
#define MAX_FLINK (256)
int *flink, *dynamicFlink = NULL, staticFlink[MAX_FLINK];
int patternLen = strlen(pattern);
int subjectLen = strlen(subject);
int found = 0;
int i,j;
if (patternLen > MAX_FLINK) { /* -1 for NULL terminator */
dynamicFlink = malloc(patternLen * sizeof(int));
if (dynamicFlink == NULL) {
fprintf(stderr, "malloc failure, line %d, file: %s, exiting...\n",
__LINE__, __FILE__);
exit(1);
}
flink = dynamicFlink;
}
else {
flink = staticFlink;
}
/* Step 1: Constuct Flowchart */
flink[0] = -1; /* -1 == read next char */
for(i = 1; i < patternLen; i++) {
j = flink[i-1];
while((j >= 0) && (pattern[j] != pattern[i-1])) {
j = flink[j];
}
flink[i] = j+1;
}
/* Step 2: Scan Algorithm */
for (i = j = 0; i < subjectLen; i++, j++) {
while((j >= 0) && (pattern[j] != subject[i])) {
j = flink[j];
}
if (j == patternLen-1) {
found = 1;
goto exit;
}
}
exit:
if (dynamicFlink != NULL) free(dynamicFlink);
if (!found)
return(NULL);
else
return(&subject[i-patternLen+1]);
#undef MAX_FLINK
}
/******************************************************************************
*
* GetShortVendorName - return short vendor string
*
* Description:
* some vendor strings are verbose. This function will return a shortest
* vendor name it can given an arbitrary vendor string. The returned string
* is allocated with malloc, it should be freed when no longer in use. The
* input string is not freed or modified by this function.
*
* Returns:
* pointer to allocated string
*
* Side Effects:
* string allocation, string should be freed when no longer needed.
*
* Errors:
* no errors, if function fails the string "unknown" is returned
*
* Revision History:
* Revision 0: Author: John R. Dennis Date: Mon Aug 8 16:30:53 1994
* Initial Release
*
*****************************************************************************/
static char *
GetShortVendorName(char *input)
{
int i;
char *s1 = NULL; /* s1 is temp work string */
char *s2 = NULL; /* s2 is string to return */
/* duplicate input string so that we can modify it */
s1 = strdup(input);
/* upcase string */
for (i = 0; s1[i]; i++)
if (islower(s1[i])) s1[i] = toupper(s1[i]);
/* return a short name if possible, some vendor names are verbose */
if (StringSearch(s1, "DEC") ||
StringSearch(s1, "DECWINDOWS") ||
StringSearch(s1, "Digital Equipment Corporation") ||
StringSearch(s1, "DigitalEquipmentCorporation"))
s2 = strdup("DEC");
else if (StringSearch(s1, "SGI") ||
StringSearch(s1, "SILCON GRAPHICS"))
s2 = strdup("SGI");
else if (StringSearch(s1, "IBM") ||
StringSearch(s1, "INTERNATIONAL BUSINESS MACHINES"))
s2 = strdup("IBM");
else
s2 = strdup(s1);
free(s1);
return(s2);
}
/******************************************************************************
*
* GetHostMemorySize - Return kilobytes of memory installed on host platform
*
* Description:
* Returns the number of kilobytes of memory installed on host platform
*
* Returns:
* kilobytes of host platform memory
*
* Side Effects:
* None
*
* Errors:
* return 0 if unable to determine memory configuration
*
* Revision History:
* Revision 0: Author: John R. Dennis Date: Thu Aug 4 15:55:19 1994
* Initial Release
*
*****************************************************************************/
static int
GetHostMemorySize(void)
{
/* AvailMem */
return (24 * 1024 * 1024) / 1024;
}
/******************************************************************************
*
* GetHostVendor - return string naming the system vendor
*
* Description:
* return the name of the system vendor as a string. This is to identify
* manufacturer of the system. The string is allocated with malloc, it should
* be freed when no longer in use.
*
* Returns:
* pointer to allocated string
*
* Side Effects:
* string allocation, string should be freed when no longer needed.
*
* Errors:
* no errors, if function fails the string "unknown" is returned
*
* Revision History:
* Revision 0: Author: John R. Dennis Date: Mon Aug 8 16:30:53 1994
* Initial Release
*
*****************************************************************************/
static char *
GetHostVendor(void)
{
/* See if it's a DEC system */
char *hostModel;
hostModel = GetHostModel();
if ( strstr(hostModel,"DEC") == hostModel)
{
free(hostModel);
return(strdup("DEC"));
}
else
{
free(hostModel);
return(strdup("unknown"));
}
}
/******************************************************************************
*
* GetHostModel - return string naming the host model
*
* Description:
* return string identifying the host platform's model designation. The string
* is allocated with malloc, it should be freed when no longer in use.
*
* Returns:
* pointer to allocated string
*
* Side Effects:
* string allocation, string should be freed when no longer needed.
*
* Errors:
* no errors, if function fails the string "unknown" is returned
*
* Revision History:
* Revision 0: Author: John R. Dennis Date: Mon Aug 8 16:30:53 1994
* Initial Release
*
*****************************************************************************/
static char *
GetHostModel(void)
{
return strdup("AmigaOS");
}
/******************************************************************************
*
* GetHostCPU - return string naming the host CPU
*
* Description:
* return string identifying the host platform's CPU. The string
* is allocated with malloc, it should be freed when no longer in use.
*
* Returns:
* pointer to allocated string
*
* Side Effects:
* string allocation, string should be freed when no longer needed.
*
* Errors:
* no errors, if function fails the string "unknown" is returned
*
* Revision History:
* Revision 0: Author: John R. Dennis Date: Mon Aug 8 16:30:53 1994
* Initial Release
*
*****************************************************************************/
static char *
GetHostCPU(void)
{
return strdup("Motorola MC68030 (30MHz), MC68882 (30MHz)");
}
/******************************************************************************
*
* GetHostCPUCount - return string indica